<?php
use yii\widgets\Breadcrumbs;
use yii\helpers\Html;
use yii\grid\GridView;
use \yii\db\Query;
use yii\widgets\ActiveForm;
use app\modules\clinical\models\Patient;

$this->title = '家属关系';
$this->params['breadcrumbs'][] = ['label' => '临床信息', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

GLOBAL $rels;
$rels = $rel;
?>

<?= Breadcrumbs::widget([
  'homeLink' => ['label' => '医疗管理系统', 'url' => '#'],
  'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>

<div class="patient-relative">

	<p>
      <?= Html::a('创建亲属关系', ['create'], ['class' => 'btn btn-success']) ?>
  </p>

	<?= GridView::widget([
    // 'filterModel' => $searchModel,
    'dataProvider' => $dataProvider,
    'columns' => [

      ['class' => 'yii\grid\SerialColumn'],

      [
          'attribute' => '亲属关系',
          'value' => function($data) {
          		GLOBAL $rels;
              return Patient::getParams('relation', $rels[$data->pk_id]);
          },
      ],
      'pt_name',
      [
          'attribute' => 'pt_sex',
          'value' => function($data) {
              return Patient::getParams('sex', $data->pt_sex);
          },
      ],
      'pt_birth',
      [
      		'attribute' => 'pt_nation',
      		'value' => function($data) {
              return Patient::getParams('nation', $data->pt_nation);
          },
      ],
      [
      		'attribute' => 'pt_marry',
      		'value' => function($data) {
              return Patient::getParams('marry', $data->pt_marry);
          },
      ],
      [
          'class' => 'yii\grid\ActionColumn',
          'buttons' =>[
              'view' => function($url, $model, $key) {
                  return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', '/clinical/relative/view?id='.$key);
              },
              'enter' => function($url, $model, $key) {
                  return Html::a('<i class="fa fa-paper-plane"></i>', '/search/search/enter?id='.$key.'&name='.$model->pt_name.'&dna='.$model->dna_id);
              },
              'delete' => function($url, $model, $key) {
                  GLOBAL $rels;
                  $rel = Patient::getParams('relation', $rels[$model->pk_id]);
                  return Html::a('<i class="glyphicon glyphicon-trash"></i>', ['relative/delete', 'id' => $model->pk_id], [
                    'data' => [
                        'confirm' => '确定删除 '.$rel.' '.$model->pt_name.' ?',
                        'method' => 'post',
                  ]]);
              },
          ],
          'template' => '{view} {enter} {delete}',
      ],
    ],
	]); ?>

</div>